package io.cloud.tec.ant_design_vue_pro.biz;

import io.cloud.tec.ant_design_vue_pro.dao.JdbcMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.concurrent.TimeUnit;

@Slf4j
@Service
@AllArgsConstructor
public class JdbcService {

    private JdbcMapper jdbcMapper;

    @Transactional
    public void jdbc() {
//        try {
//            String s1 = jdbcMapper.sql("insert into data_log (ctime) values(now())");
            String s1 = jdbcMapper.sql("update data_log set ctime= '2023-08-13' where id = 1");
            String s3 = jdbcMapper.sql("update data_log set ctime= '2023-08-14' where id = 2");
//            log.info(s1);
//            TimeUnit.SECONDS.sleep(65);
//            String s2 = jdbcMapper.sql("update data_log set ctime= now() where id = 3");
//            log.info(s2);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
    }

    public void createTable() {
        jdbcMapper.sql("drop table if EXISTS data_log; create table data_log (id bigint AUTO_INCREMENT primary key, ctime datetime);");
    }
}
